package edu.cth.scrabbit.client.view.panels;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.LayoutStyle;

import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.ApplicationActionMap;

import edu.cth.scrabbit.client.ctrl.ClientController;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ActionsPanel extends javax.swing.JPanel {
	private JButton passButton;
	private JButton placeButton;
	private JButton clearButton;
	private JButton swapButton;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
		
	public ActionsPanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(168, 136));
			{
				passButton = new JButton();
			
				passButton.setAction(getAppActionMap().get("passGameAction"));
			}
			{
				swapButton = new JButton();
			
				swapButton.setAction(getAppActionMap().get("swapGameAction"));
				swapButton.setSize(59, 24);
			}
			
			{
				placeButton = new JButton();
				;
				placeButton.setAction(getAppActionMap().get("placeWordGameAction"));
				placeButton.setName("placeButton");
				placeButton.setSize(59, 24);
			}
			{
				clearButton = new JButton();
				clearButton.setName("clearButton");
				clearButton.setSize(59, 24);
				clearButton.setAction(getAppActionMap().get("clearAction"));
				clearButton.setAction(getAppActionMap().get("clearAction"));
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(placeButton, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(passButton, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(clearButton, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(swapButton, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
					.addGap(0, 7, Short.MAX_VALUE));
				thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(thisLayout.createParallelGroup()
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(placeButton, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE))
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(passButton, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE))
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(clearButton, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE))
					    .addGroup(thisLayout.createSequentialGroup()
					        .addComponent(swapButton, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(11, Short.MAX_VALUE));
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		passButton.setText("Pass");
		swapButton.setText("Swap");
	}
	
	@Action
	public void passGameAction() {
		ClientController.getInstance().pass();
	}
	
    /**
    * Returns the action map used by this application.
     * Actions defined using the Action annotation
     * are returned by this method
     */
	private ApplicationActionMap getAppActionMap() {
		return Application.getInstance().getContext().getActionMap(this);
	}
	
	@Action
	public void swapGameAction() {
		ClientController.getInstance().swap();
	}
	
	@Action
	public void placeWordGameAction() {
		ClientController.getInstance().play();
	}
	
	@Action
	public void clearAction() {
		ClientController.getInstance().clear();
	}
	
	public void setButtonsEnabled(boolean b) {
		passButton.setEnabled(b);
		placeButton.setEnabled(b);
		clearButton.setEnabled(b);
		swapButton.setEnabled(b);
	}

}
